#!/usr/bin/python
# -*-coding: UTF-8 -*-
"""
# Time: 2021/11/1 23:35
# @Author: 修养
# @Project_name: PROJECT_NAME
"""
import json

list1 = ["乔峰", "段誉"]
list_dumps = json.dumps(list1, ensure_ascii=False)
print('list_dumps = ', list_dumps, '类型：', type(list_dumps))


dict1 = {"name1": "乔峰", "id": '1001'}
dict_dumps = json.dumps(dict1, ensure_ascii=False)
print('dict_dumps = ', dict_dumps, '类型：', type(dict_dumps))

# 列表
data = [{'id': '1001', 'name': '李白', 'gender': '男'}, {'age': '300', 'hobby': '写诗'}]
print('data = ', data, 'data类型：', type(data))
# 列表转字符串  json.dumps()方法默认将中文以ascii码输出
data_dumps = json.dumps(data, ensure_ascii=False)
print('data_dumps = ', data_dumps, '类型：', type(data_dumps), )

print('·~~~~~~~~~~~~~~~~字典转换：~~~~~~~~~~~~~~~~')
# 字符串转字典
dict_str = '{"a":1,"b":2,"c":3,"d":4,"e":5}'
print('jsonData = ', dict_str, '类型：', type(dict_str))
dicts = json.loads(dict_str)
print('dicts = ', dicts, '类型：', type(dicts))

# 字符串转列表
list_str = '["虚竹", "大师"]'
lists = json.loads(list_str)
print('lists = ', lists, '类型:', type(lists))